package com.yycx.module.bus.provider.handler.calculate;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.interceptor.GetInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.module.bus.client.entity.*;
import com.yycx.module.bus.provider.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单核算tab详情查询
 *
 * @author zyf
 */
@Component("calCulateTab1GetHandler")
public class CalCulateTab1GetHandler implements GetInterceptor {


    @Autowired
    private BusOrderService orderService;
    @Autowired
    private BusCustomService customService;

    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {

    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long customId = map.getLong("customId");
        Integer orderState=map.getInt("orderState");
        //是否允许核算
        Boolean calculate = OpenHelper.hasRole("ROLE_ZJL","ROLE_ZJL_LD","ROLE_KJ","ROLE_NQBZ","ROLE_CWBZ","ROLE_KJ_LD","ROLE_NQBZ_LD","ROLE_CWBZ_LD");
        if(orderState.equals(2)){
            calculate = OpenHelper.hasRole("ROLE_ZJL","ROLE_ZJL_LD","ROLE_CWBZ","ROLE_CWBZ_LD","ROLE_NQBZ_LD","ROLE_KJ_LD");
        }
        map.put("calculate", calculate);
        Long orderId = map.getLong("orderId");
        BusOrder order = orderService.getById(orderId);
        if (calculate) {

            map.put("supplierBondType", order.getSupplierBondType());
            map.put("customBondType", order.getCustomBondType());

        }
        map.put("sendNo", order.getSendNo());
        map.put("customFpId", order.getCustomFpId());
        map.put("sendAttachment", order.getSendAttachment());
        map.put("invoiceAttachment", order.getInvoiceAttachment());
        BusCustom busCustom=customService.getById(customId);
        if(FlymeUtils.isNotEmpty(busCustom)){
            Boolean settleType=busCustom.getSettleType();
            if(settleType){
                map.put("settleType", 1);
            }else{
                map.put("settleType", 0);
            }
        }
    }

}
